package com.woniu.util;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**
 * @Classname TopicConsumer
 * @Description TODO
 * @Date 2025/10/24 16:04
 * @Created by pc
 */
@Component
public class TopicConsumer {

    @RabbitListener(queues = {"topicQueue"})
    public void consume(String code, Channel channel, Message message){
        System.out.println("code:" + code);
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            // throw new RuntimeException(e);
            e.printStackTrace();
            try {
                channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,false);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
}
